/**
 * 
 */
package com.thon.controller.home;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.thon.controller.util.BaseController;
import com.thon.service.user.UserService;

/**
 * @file HomeController.java
 * @author thon
 * @email thon.ju@gmail.com
 * @date Aug 19, 2013 7:37:53 PM
 * @description TODO
 */

@Controller
@RequestMapping(value = "/home")
public class HomeController extends BaseController{
	
	private static final Log log = LogFactory.getLog(HomeController.class);

	@Autowired
	private UserService userService;
	
	@ModelAttribute
	public void init(Model model) {
		if (!SecurityUtils.getSubject().isAuthenticated()){
			return;
		}
		
		int userId = getCurrentUserId();
		model.addAttribute("user", userService.getUser(userId));
	}
	
	@RequestMapping(method = RequestMethod.GET)
	public String home(Map<String, Object> map) {
		
		log.debug("");
		
		return "home";
	}
	
	
	@RequestMapping(value="/profile",method = RequestMethod.GET)
	public String profile(Map<String, Object> map) {
		
		log.debug("profile");
		
		return "profile";
	}
	
	@RequestMapping(value="/{id}",method = RequestMethod.GET)
	public String user(@PathVariable("id") String id, Map<String, Object> map) {
		
		log.debug("user");
		
		return "user";
	}
	
	@RequestMapping(value="/message",method = RequestMethod.GET)
	public String message(Map<String, Object> map) {
		
		log.debug("message");
		
		return "message";
	}
	
	@RequestMapping(value="/message/coupon",method = RequestMethod.GET)
	public String messagecoupon(Map<String, Object> map) {
		
		return "msgcoupon";
	}
}
